﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.SmartTriggerActions.Service
{
    public class SmartTriggerActionAppService : BaseAppService, ISmartTriggerActionAppService
    {
        private ISmartTriggerActionDomainService _domainService;

        public SmartTriggerActionAppService(ISmartTriggerActionDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SMARTTRIGGERACTION, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SMARTTRIGGERACTION, AuditAction.CREATE)]
        public SmartTriggerActionDto Add(Guid smartTriggerId, SmartTriggerActionCreateDto dto)
        {
            dto.Id = Guid.NewGuid();
            dto.SmartTriggerId = smartTriggerId;
            SmartTriggerAction smartTriggerAction = _domainService.Create(Mapper.Map<SmartTriggerAction>(dto));
            return Mapper.Map<SmartTriggerActionDto>(smartTriggerAction);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        [Audit(BotEntity.SMARTTRIGGERACTION, AuditAction.UPDATE)]
        public SmartTriggerActionDto Update(Guid id, SmartTriggerActionUpdateDto dto)
        {
            dto.Id = id;
            SmartTriggerAction smartTriggerAction = _domainService.Update(Mapper.Map<SmartTriggerActionUpdateBo>(dto));
            return Mapper.Map<SmartTriggerActionDto>(smartTriggerAction);
        }

        public SmartTriggerActionDto Get(Guid id)
        {
            SmartTriggerAction smartTriggerAction = _domainService.Get(id);
            return Mapper.Map<SmartTriggerActionDto>(smartTriggerAction);
        }

        public IEnumerable<SmartTriggerActionDto> GetList(Guid smartTriggerId)
        {
            IEnumerable<SmartTriggerAction> list = _domainService.GetBySmartTriggerId(smartTriggerId);
            return Mapper.Map<IEnumerable<SmartTriggerActionDto>>(list);
        }
    }
}
